local yanjie = fk.CreateSkill{
    name = "wk_heg__yanjie",
}

Fk:loadTranslationTable{
  ["wk_heg__yanjie"] = "严诫",
  [":wk_heg__yanjie"] = "当你于出牌阶段内首次对自己使用牌结算后，你可令一名角色弃置一张牌，若这两张牌类型相同，其视为使用【无中生有】，若其与你势力相同，其可改为<a href=':ElectedChange'>推举</a>。",

  ["#wk_heg__yanjie-choose"] = "严诫：选择一名角色，令其弃置一张牌",
  ["#wk_heg__yanjie-discard"] = "严诫：请弃置一张牌，若与使用牌类型相同，你视为使用【无中生有】",
  ["wk_heg__yanjie_doelected"] = "推举",
  ["wk_heg__yanjie_usecard"] = "视为使用【无中生有】",

  ["$wk_heg__yanjie1"] = "上兵伐谋，三思而行。",
  ["$wk_heg__yanjie2"] = "精益求精，慎之再慎。",
}

local H = require "packages.ol_hegemony.util"
local HG = require "packages.new_heg_diy_my.util"

yanjie:addEffect(fk.CardUseFinished,{
  anim_type = "special",
  can_trigger = function (self, event, target, player, data)
    if not (player:hasSkill(yanjie.name) and target == player and player.phase == Player.Play and data.tos and table.find(data:getAllTargets(), function(p) return p == player end)) then return false end
    local events = player.room.logic:getEventsOfScope(GameEvent.UseCard, 2, function(e)
      local use = e.data
      return use.from == player and table.contains(use:getAllTargets(), player)
    end, Player.HistoryPhase)
    return #events == 1
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local targets = room.alive_players
    local tos = room:askToChoosePlayers(player,{
      targets = targets,
      min_num = 1,
      max_num = 1,
      prompt = "#wk_heg__yanjie-choose",
      skill_name = yanjie.name
    })
    if #tos > 0 then
      local to = tos[1]
      local cards = room:askToDiscard(to,{
          min_num = 1,
          max_num = 1,
          include_equip = true,
          skill_name = yanjie.name,
          cancelable = false,
          prompt = "#wk_heg__yanjie-discard",
      })
      if Fk:getCardById(cards[1]).type == data.card.type then
        if H.compareKingdomWith(to, player) then
          local choices = {"wk_heg__yanjie_doelected", "wk_heg__yanjie_usecard"}
          local choice = room:askToChoice(to, {choices = choices, skill_name = yanjie.name})
          if choice == "wk_heg__yanjie_usecard" then
            room:useVirtualCard("ex_nihilo", nil, to, to, yanjie.name)
          else
            HG.DoElectedChange(room, to, yanjie.name)
          end
        else
          room:useVirtualCard("ex_nihilo", nil, to, to, yanjie.name)
        end
      end
    end
  end,
})

return yanjie